package leetcode.code2233;

import java.util.PriorityQueue;

import leetcode.IDebug;

public class Solution implements IDebug {

	int mod = (int) 1e9 + 7;

	public int maximumProduct(int[] nums, int k) {
		PriorityQueue<Integer> queue = new PriorityQueue<>();
		for (int i = 0; i < nums.length; i++) {
			queue.add(nums[i]);
		}
		while (k > 0) {
			int cur = queue.poll();
			int next = queue.isEmpty() ? 0 : queue.peek();
			int diff = Math.max(Math.min(next - cur, k), 1);
			k -= diff;
			cur += diff;
			queue.add(cur);
		}
		long ans = 1;
		while (!queue.isEmpty()) {
			ans *= queue.poll();
			ans %= mod;
		}
		return (int) ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
